Let us consider a circuit consisting of
gates. The gates are numbered from
to
. Each gate has a certain number of inputs and exactly one output. Each of them (inputs and outputs) may be in either one of the states
,
or
. Each input is connected to exactly one output of some gate. Input's state equals the state of the output it is connected to. Each output may be connected to an arbitrary number of inputs. The gates with numbers
and
are special - they don't have any input at all while their outputs are always in the following states:
for a gate with a number
,
for a gate with a number
. We say that the state of the output of a gate (in short: gate's state) is valid, if:
and the gate has more inputs in state
than in state
.
and the gate has the same number of inputs in state
as in state
.
and the gate has more inputs in state
than it has in state
.
or
, and its state is
or
respectively. We say that a circuit's state is valid if all the states of its gates are valid. We say that a gate's state is fixed if the gate is in the same state in all circuit's valid states.
Write a programme that:
The first line of the standard input contains the number of gates
,
. The following
lines contain the descriptions of gates' connections - line no.
describes inputs of the gate no.
. There is the number
of inputs of this gate, followed by
numbers of gates,
. Those are the numbers of gates whose outputs are connected to successive inputs of the gate's no.
. Numbers in each line are separated by single spaces. The total number of all inputs of all gates does not exceed
.
Your programme should write
lines to the standard output. Depending on the state of gate no.
,
'th line should contain:
,
,
,For the input data:
5 2 0 1 2 4 2 2 2 4
the correct result is:
0 1 1/2 ? ?

Task author: Bartosz Walczak.
W razie problemów technicznych ze Szkopułem, prosimy o kontakt mailowy pod adresem szkopul@fri.edu.pl.
Jeśli chciałbyś porozmawiać o zadaniach, rozwiązaniach lub problemach technicznych, odwiedź nasze serwery na Discordzie. Są one moderowane przez społeczność, ale członkowie zespołu wsparcia również aktywnie się tam udzielają.